extends Node2D


# Declare member variables here. Examples:
# var a = 2
# var b = "text"

onready var panel_height = 0.2 * get_viewport().size.y
var BG_COLOR = ColorN("black")
var bg_rect


var ping_ratio = 0.2
var time_left_v_ratio = 0.3 

var planet
onready var target_y = -panel_height*2



var ping_rect
var jam_progress_bar
var time_left_bar

func activate(_planet):
	print("top_panel activated")
	planet = _planet
	target_y = 0.0
	for c in [time_left_bar,jam_progress_bar,ping_rect]:
		c.activate()

func deactivate():
	for c in [time_left_bar,jam_progress_bar,ping_rect]:
		c.deactivate()
	planet = null
	target_y = -panel_height*2

# Called when the node enters the scene tree for the first time.
func _ready():
	var ping_rect_width
	var progress_width
	ping_rect_width = get_viewport().size.x * ping_ratio
	progress_width = get_viewport().size.x - ping_rect_width
	var time_left_bar_height = time_left_v_ratio*panel_height
	var jam_progress_bar_height = panel_height - time_left_bar_height
	
	bg_rect = ColorRect.new()
	bg_rect.rect_size = Vector2(get_viewport().size.x, panel_height)
	bg_rect.color = ColorN("black")
	call_deferred("add_child", bg_rect)
	
	ping_rect = PingRect.new()
	ping_rect.rect_size = Vector2(ping_rect_width,panel_height)

	call_deferred("add_child",ping_rect)
	
	jam_progress_bar = JamProgressBar.new()
	jam_progress_bar.rect_position = Vector2(ping_rect_width,0)
	jam_progress_bar.rect_size = Vector2(progress_width,jam_progress_bar_height)

	call_deferred("add_child",jam_progress_bar)
	
	time_left_bar = TimeLeftBar.new()
	time_left_bar.rect_position = Vector2(ping_rect_width,jam_progress_bar_height)
	time_left_bar.rect_size = Vector2(progress_width,time_left_bar_height)

	call_deferred("add_child",time_left_bar)
	
	pass # Replace with function body.

func _process(delta):
	position.y += (target_y - position.y)*0.11
